package com.ymatou.iapi.productprice.testcase;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.shop2cn.iapi.activitymgt.parameter.AddactivityBean;
import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.ProductDetailsDto;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productprice.service.GetPriceByProdIdCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.*;
import com.ymttest.database.model.YmtCatalogsI;
import com.ymttest.database.mongo.jproduct.ProductTimeStampWapper;
import com.ymttest.database.mongo.jproduct.ProductsWapperV2;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.utils.AgentUsers;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.MapUtil;
import com.ymttest.utils.YMTDateUtil;
import org.json.JSONArray;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

public class Ts_GetPriceByProdIdV2 {

    private static int oldBuyerId = ProductPriceCallService.getOldCustomer();
    private static GetPriceByProdIdCall getPriceByProdIdCall = new GetPriceByProdIdCall();
    private static ProductTimeStampWapper productTimeStampWapper = new ProductTimeStampWapper();
    private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
    private static ProductPriceCallService priceCallService = new ProductPriceCallService();
    @BeforeClass
    public static void setUp() {
        Logger.createResultFile("非交易隔离查询接口, 根据商品id查询商品价格，多活动");
    	try {
			GodfreightmgrService.deleteBySellerId(rootUserId);
		} catch (IOException e) {
			e.printStackTrace();
		}
    }

    @Before
    public void caseUp() {

    }

    @AfterClass
    public static void tearDown() {
        Logger.generateResult(getPriceByProdIdCall.getOpurl());
    }

    @After
    public void caseDown() {
        Logger.end();
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_GetPriceByProdId_001() {
        Logger.start(true, "非交易隔离,单活动");
        try {
            AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
            String productId = ProductManagerCallServiceV3.AddSellerProduct(addpro);
            //获取规格ID
            List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
            //创建一个高优先级活动  得到活动id
            Integer activityId = ProductManagerCallServiceV2.createNoIsolationActivityInProcess();
            //报名活动  获得商品在活动中的id
            String price1 = "8.0";
            List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,price1);
            //审核通过
            ProductManagerCallServiceV2.approveProductInActivityV2(productId,aids.get(0),true);
            new ProductsWapperV2().updateActivityProductByProductId(MapUtil.hashMap("aid",activityId),MapUtil.hashMap("start",
                    YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getBeforeOrNextSecond(-3600)),"end",YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getBeforeOrNextSecond(3600))));

            Logger.debug(new ProductsWapperV2().getActivityProductByProductId(productId));
            JsonObject ret = getPriceByProdIdCall.callAndGetReturnData(oldBuyerId,productId);
            JsonObject retbean = ret.get("Data").getAsJsonObject().get("PriceInfo").getAsJsonObject();
            JsonArray catalogsJsonArray = retbean.get("Catalogs").getAsJsonArray();
            Logger.verifyEquals("200", ret.get("Code").getAsString(), "报文返回code检查");
            //验证当前价格是高优先级价格
            for (int i = 0; i < catalogsJsonArray.size(); i++) {
                JsonObject catalogInfo = catalogsJsonArray.get(i).getAsJsonObject();
                Logger.verifyEquals(price1,catalogInfo.get("Price").getAsString(),"验证价格");
                Logger.verifyEquals(price1,catalogInfo.get("ActivityPrice").getAsString(),"验证活动价格");
            }
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_GetPriceByProdId_004() {
        Logger.start(true, "非交易隔离,一段时间内同时存在两个不同优先级的活动");
        try {
            AddSellerProductRequest addpro =  ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
            ProductManagerCallServiceV3.AddSellerProduct(addpro);
            String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
            //获取规格ID
            List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
            //创建一个高优先级活动  得到活动id
            Integer activityId = ProductManagerCallServiceV2.createNoIsolationActivityInProcess();
            //报名活动  获得商品在活动中的id
            String price1 = "8.0";
            List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,price1);
            //审核通过
            ProductManagerCallServiceV2.approveProductInActivityV2(productId,aids.get(0),true);
            //创建一个低优先级活动  得到活动id
//            Integer activityId1 = ProductManagerCallServiceV2.createNoIsolationActivityInProcessV2();
            //update by summing 20210126 创建一个非交易隔离的低优先级活动
            Integer activityId1 = ProductManagerCallServiceV2.createNoIsolationAndLowActivityInProcess();
            String price2 = "9.0";
            List<String> aids1 = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId1, 100,price2);
            ProductManagerCallServiceV2.approveProductInActivityV2(productId,aids1.get(0),true);

            new ProductsWapperV2().updateActivityProductByProductId(MapUtil.hashMap("aid",activityId),MapUtil.hashMap("start",
                    YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getBeforeOrNextSecond(-3600)),"end",YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getBeforeOrNextSecond(3600))));
            new ProductsWapperV2().updateActivityProductByProductId(MapUtil.hashMap("aid",activityId1),MapUtil.hashMap("start",
                    YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getBeforeOrNextSecond(-3600)),"end",YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getBeforeOrNextSecond(3600))));
            new ProductsWapperV2().updateActivityProductByProductId(MapUtil.hashMap("aid",activityId1),MapUtil.hashMap("isolation",false));
            productTimeStampWapper.update(productId, MapUtil.hashMap("aut",new Date(),"cut",new Date()));

            JsonObject ret = getPriceByProdIdCall.callAndGetReturnData(oldBuyerId,productId);
            JsonObject retbean = ret.get("Data").getAsJsonObject().get("PriceInfo").getAsJsonObject();
            JsonArray catalogsJsonArray = retbean.get("Catalogs").getAsJsonArray();
            Logger.verifyEquals("200", ret.get("Code").getAsString(), "报文返回code检查");
            //验证当前价格是高优先级价格
            for (int i = 0; i < catalogsJsonArray.size(); i++) {
                JsonObject catalogInfo = catalogsJsonArray.get(i).getAsJsonObject();
                Logger.verifyEquals(price1,catalogInfo.get("Price").getAsString(),"验证价格");
                Logger.verifyEquals(price1,catalogInfo.get("ActivityPrice").getAsString(),"验证活动价格");
            }
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_GetPriceByProdId_002() {
        Logger.start(true, "非交易隔离,一段时间内同时存在两个不同优先级的活动,低优先级先开始，高优先级未开始");
        try {
            AddSellerProductRequest addpro =  ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
            ProductManagerCallServiceV3.AddSellerProduct(addpro);
            String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
            //获取规格ID
            List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
            //创建一个高优先级活动  得到活动id
            Integer activityId = ProductManagerCallServiceV2.createNoIsolationActivityInProcess();
            //报名活动  获得商品在活动中的id
            String price1 = "8.0";
            List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,price1);
            //审核通过
            ProductManagerCallServiceV2.approveProductInActivityV2(productId,aids.get(0),true);
            //创建一个低优先级活动  得到活动id
           // Integer activityId1 = ProductManagerCallServiceV2.createNoIsolationActivityInProcessV2();
            //update by summing 20210126 创建一个非交易隔离的低优先级活动
            Integer activityId1 = ProductManagerCallServiceV2.createNoIsolationAndLowActivityInProcess();

            String price2 = "9.0";
            List<String> aids1 = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId1, 100,price2);
            ProductManagerCallServiceV2.approveProductInActivityV2(productId,aids1.get(0),true);
            //activityId高优先级活动id  activetyId1 低优先级活动
            new ProductsWapperV2().updateActivityProductByProductId(MapUtil.hashMap("aid",activityId1),MapUtil.hashMap("start",
                    YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getBeforeOrNextSecond(-3600)),"end",YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getBeforeOrNextSecond(36000))));
            new ProductsWapperV2().updateActivityProductByProductId(MapUtil.hashMap("aid",activityId),MapUtil.hashMap("start",
                    YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getBeforeOrNextSecond(3600)),"end",YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getBeforeOrNextSecond(36000))));
            new ProductsWapperV2().updateActivityProductByProductId(MapUtil.hashMap("aid",activityId1),MapUtil.hashMap("isolation",false));

            productTimeStampWapper.update(productId, MapUtil.hashMap("aut",new Date(),"cut",new Date()));
            JsonObject ret = getPriceByProdIdCall.callAndGetReturnData(oldBuyerId,productId);
            JsonObject retbean = ret.get("Data").getAsJsonObject().get("PriceInfo").getAsJsonObject();
            JsonArray catalogsJsonArray = retbean.get("Catalogs").getAsJsonArray();
            Logger.verifyEquals(200, ret.get("Code").getAsInt(), "报文返回code检查");
            //验证当前价格是高优先级价格
            //低优先级
            for (int i = 0; i < catalogsJsonArray.size(); i++) {
                JsonObject catalogInfo = catalogsJsonArray.get(i).getAsJsonObject();
                Logger.verifyEquals(price2,catalogInfo.get("Price").getAsString(),"验证价格");
                Logger.verifyEquals(price2,catalogInfo.get("ActivityPrice").getAsString(),"验证活动价格");
            }

        } catch (Exception e) {
            Logger.fail(e);
        }
    }


    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_GetPriceByProdId_003() {
        Logger.start(true, "非交易隔离,一段时间内同时存在两个不同优先级的活动,高优先级库存卖完");
        try {
            AddSellerProductRequest addpro =  ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
            ProductManagerCallServiceV3.AddSellerProduct(addpro);
            String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
            //获取规格ID
            List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
            //创建一个高优先级活动  得到活动id
            Integer activityId = ProductManagerCallServiceV2.createNoIsolationActivityInProcess();
            //报名活动  获得商品在活动中的id
            String price1 = "8.0";
            List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,price1);
            //审核通过
            ProductManagerCallServiceV2.approveProductInActivityV2(productId,aids.get(0),true);
            //创建一个低优先级活动  得到活动id
          //  Integer activityId1 = ProductManagerCallServiceV2.createNoIsolationActivityInProcessV2();
            //update by summing 20210126 创建一个非交易隔离的低优先级活动
            Integer activityId1 = ProductManagerCallServiceV2.createNoIsolationAndLowActivityInProcess();
            String price2 = "9.0";
            List<String> aids1 = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId1, 100,price2);
            ProductManagerCallServiceV2.approveProductInActivityV2(productId,aids1.get(0),true);

            //activityId高优先级活动id  activetyId1 低优先级活动
            new ProductsWapperV2().updateActivityProductByProductId(MapUtil.hashMap("aid",activityId),MapUtil.hashMap("start",
                    YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getBeforeOrNextSecond(-3600)),"end",YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getBeforeOrNextSecond(36000))));
            new ProductsWapperV2().updateActivityProductByProductId(MapUtil.hashMap("aid",activityId1),MapUtil.hashMap("start",
                    YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getBeforeOrNextSecond(-3600)),"end",YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getBeforeOrNextSecond(36000))));
            new ProductsWapperV2().updateActivityProductByProductId(MapUtil.hashMap("aid",activityId1),MapUtil.hashMap("isolation",false));
            priceCallService.updateActivityStockTo0InMgo(Integer.parseInt(aids.get(0)));
            productTimeStampWapper.update(productId, MapUtil.hashMap("aut",new Date(),"cut",new Date()));
            JsonObject ret = getPriceByProdIdCall.callAndGetReturnData(oldBuyerId,productId);
            JsonObject retbean = ret.get("Data").getAsJsonObject().get("PriceInfo").getAsJsonObject();
            JsonArray catalogsJsonArray = retbean.get("Catalogs").getAsJsonArray();
            Logger.verifyEquals("200", ret.get("Code").getAsString(), "报文返回code检查");
            //验证当前价格是高优先级价格
            for (int i = 0; i < catalogsJsonArray.size(); i++) {
                JsonObject catalogInfo = catalogsJsonArray.get(i).getAsJsonObject();
                Logger.verifyEquals(price2,catalogInfo.get("Price").getAsString(),"验证价格");
                Logger.verifyEquals(price2,catalogInfo.get("ActivityPrice").getAsString(),"验证活动价格");
            }

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_GetPriceByProdId_005() {
        Logger.start(true, "非交易隔离,一段时间内同时存在两个不同优先级的活动,高优先级和低优先级库存都卖完，显示原价");
        try {
            AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
            String price = "16";
            addpro.getProduct().getCatalogList().forEach(p->{
                p.setVipPrice(0);
                p.setPrice(Integer.parseInt(price));
            });
            ProductManagerCallServiceV3.AddSellerProduct(addpro);
            String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
            //获取规格ID
            List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
            //创建一个高优先级活动  得到活动id
            Integer activityId = ProductManagerCallServiceV2.createNoIsolationActivityInProcess();
            //报名活动  获得商品在活动中的id
            String price1 = "8.0";
            List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,price1);
            //审核通过
            ProductManagerCallServiceV2.approveProductInActivityV2(productId,aids.get(0),true);
            //创建一个低优先级活动  得到活动id
          //  Integer activityId1 = ProductManagerCallServiceV2.createNoIsolationActivityInProcessV2();
            //update by summing 20210126 创建一个非交易隔离的低优先级活动
            Integer activityId1 = ProductManagerCallServiceV2.createNoIsolationAndLowActivityInProcess();
            String price2 = "9.0";
            List<String> aids1 = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId1, 100,price2);
            ProductManagerCallServiceV2.approveProductInActivityV2(productId,aids1.get(0),true);

            //activityId高优先级活动id  activetyId1 低优先级活动
            new ProductsWapperV2().updateActivityProductByProductId(MapUtil.hashMap("aid",activityId),MapUtil.hashMap("start",
                    YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getBeforeOrNextSecond(-3600)),"end",YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getBeforeOrNextSecond(36000))));
            new ProductsWapperV2().updateActivityProductByProductId(MapUtil.hashMap("aid",activityId1),MapUtil.hashMap("start",
                    YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getBeforeOrNextSecond(-3600)),"end",YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getBeforeOrNextSecond(36000))));
            new ProductsWapperV2().updateActivityProductByProductId(MapUtil.hashMap("aid",activityId1),MapUtil.hashMap("isolation",false));
            //库存卖完
            priceCallService.updateActivityStockTo0InMgo(Integer.parseInt(aids.get(0)));
            priceCallService.updateActivityStockTo0InMgo(Integer.parseInt(aids1.get(0)));
            productTimeStampWapper.update(productId, MapUtil.hashMap("aut",new Date(),"cut",new Date()));
            JsonObject ret = getPriceByProdIdCall.callAndGetReturnData(oldBuyerId,productId);
            JsonObject retbean = ret.get("Data").getAsJsonObject().get("PriceInfo").getAsJsonObject();
            JsonArray catalogsJsonArray = retbean.get("Catalogs").getAsJsonArray();
            Logger.verifyEquals(200, ret.get("Code").getAsInt(), "报文返回code检查");
            //验证当前价格是高优先级价格
            for (int i = 0; i < catalogsJsonArray.size(); i++) {
                JsonObject catalogInfo = catalogsJsonArray.get(i).getAsJsonObject();
                Logger.verifyEquals(price+".0",catalogInfo.get("Price").getAsString(),"验证价格");
                Logger.verifyEquals("0.0",catalogInfo.get("ActivityPrice").getAsString(),"验证活动价格");
            }

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_GetPriceByProdId_006() {
        Logger.start(true, "非交易隔离,报名三个活动");
        try {
            AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
            String price = "16";
            addpro.getProduct().getCatalogList().forEach(p->{
                p.setVipPrice(0);
                p.setPrice(Integer.parseInt(price));
            });
            ProductManagerCallServiceV3.AddSellerProduct(addpro);
            String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
            //获取规格ID
            List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
            //创建一个高优先级活动  得到活动id
            Integer activityId = ProductManagerCallServiceV2.createNoIsolationActivityInProcess();
            //报名活动  获得商品在活动中的id
            String price1 = "8.0";
            List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,price1);
            //审核通过
            ProductManagerCallServiceV2.approveProductInActivityV2(productId,aids.get(0),true);
            //创建一个低优先级活动  得到活动id
            //Integer activityId1 = ProductManagerCallServiceV2.createNoIsolationActivityInProcessV2();
            //update by summing 20210126 创建一个非交易隔离的低优先级活动
            Integer activityId1 = ProductManagerCallServiceV2.createNoIsolationAndLowActivityInProcess();

            String price2 = "9.0";
            List<String> aids1 = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId1, 100,price2);
            ProductManagerCallServiceV2.approveProductInActivityV2(productId,aids1.get(0),true);

            //activityId高优先级活动id  activetyId1 低优先级活动
            new ProductsWapperV2().updateActivityProductByProductId(MapUtil.hashMap("aid",activityId),MapUtil.hashMap("start",
                    YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getBeforeOrNextSecond(-3600)),"end",YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getBeforeOrNextSecond(36000))));
            new ProductsWapperV2().updateActivityProductByProductId(MapUtil.hashMap("aid",activityId1),MapUtil.hashMap("start",
                    YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getBeforeOrNextSecond(-3600)),"end",YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getBeforeOrNextSecond(36000))));
            new ProductsWapperV2().updateActivityProductByProductId(MapUtil.hashMap("aid",activityId1),MapUtil.hashMap("isolation",false));
            //库存卖完
            priceCallService.updateActivityStockTo0InMgo(Integer.parseInt(aids.get(0)));
            priceCallService.updateActivityStockTo0InMgo(Integer.parseInt(aids1.get(0)));
            productTimeStampWapper.update(productId, MapUtil.hashMap("aut",new Date(),"cut",new Date()));
            JsonObject ret = getPriceByProdIdCall.callAndGetReturnData(oldBuyerId,productId);
            JsonObject retbean = ret.get("Data").getAsJsonObject().get("PriceInfo").getAsJsonObject();
            JsonArray catalogsJsonArray = retbean.get("Catalogs").getAsJsonArray();
            Logger.verifyEquals("200", ret.get("Code").getAsString(), "报文返回code检查");
            //验证当前价格是高优先级价格
            for (int i = 0; i < catalogsJsonArray.size(); i++) {
                JsonObject catalogInfo = catalogsJsonArray.get(i).getAsJsonObject();
                Logger.verifyEquals(price+".0",catalogInfo.get("Price").getAsString(),"验证价格");
                Logger.verifyEquals("0.0",catalogInfo.get("ActivityPrice").getAsString(),"验证活动价格");
            }

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_GetPriceByProdId_007() {
        Logger.start(true, "非交易隔离,一段时间内同时存在两个不同优先级的活动,高优先级活动库存部分规格卖完，部分卖完规格显示原价");
        try {
            AddSellerProductRequest addpro =  ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
            ProductManagerCallServiceV3.AddSellerProduct(addpro);
            String price = String.valueOf(addpro.getProduct().getCatalogList().get(0).getPrice());
            String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
            //获取规格ID
            List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
            //创建一个高优先级活动  得到活动id
            Integer activityId = ProductManagerCallServiceV2.createNoIsolationActivityInProcess();
            //报名活动  获得商品在活动中的id
            String price1 = "8.0";
            List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,price1);
            //审核通过
            ProductManagerCallServiceV2.approveProductInActivityV2(productId,aids.get(0),true);
            //创建一个低优先级活动  得到活动id
          //  Integer activityId1 = ProductManagerCallServiceV2.createNoIsolationActivityInProcessV2();
            //update by summing 20210126 创建一个非交易隔离的低优先级活动
            Integer activityId1 = ProductManagerCallServiceV2.createNoIsolationAndLowActivityInProcess();
            String price2 = "9.0";
            List<String> aids1 = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId1, 100,price2);
            ProductManagerCallServiceV2.approveProductInActivityV2(productId,aids1.get(0),true);
            
            
            //activityId高优先级活动id  activetyId1 低优先级活动
            new ProductsWapperV2().updateActivityProductByProductId(MapUtil.hashMap("aid",activityId),MapUtil.hashMap("start",
                    YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getBeforeOrNextSecond(-3600)),"end",YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getBeforeOrNextSecond(36000))));
            new ProductsWapperV2().updateActivityProductByProductId(MapUtil.hashMap("aid",activityId1),MapUtil.hashMap("start",
                    YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getBeforeOrNextSecond(-3600)),"end",YMTDateUtil.parseYMDHMSDate(YMTDateUtil.getBeforeOrNextSecond(36000))));
            new ProductsWapperV2().updateActivityProductByProductId(MapUtil.hashMap("aid",activityId1),MapUtil.hashMap("isolation",false));
            // 部分规格库存卖完
            JSONArray catalogsAry = priceCallService.GetCatalogs(Integer.parseInt(aids.get(0)));
            priceCallService.updateCatalogStockInMgo(Integer.parseInt(aids.get(0)),catalogsAry);
            Logger.debug("catalogsJsonArray" + catalogsAry);

            productTimeStampWapper.update(productId, MapUtil.hashMap("aut",new Date(),"cut",new Date()));
            JsonObject ret = getPriceByProdIdCall.callAndGetReturnData(oldBuyerId,productId);
            JsonObject retbean = ret.get("Data").getAsJsonObject().get("PriceInfo").getAsJsonObject();
            JsonArray catalogsJsonArray = retbean.get("Catalogs").getAsJsonArray();

            Logger.verifyEquals("200", ret.get("Code").getAsString(), "报文返回code检查");
            //验证当前价格是高优先级价格
            for (int i = 0; i < catalogsJsonArray.size(); i++) {
                JsonObject catalogInfo = catalogsJsonArray.get(i).getAsJsonObject();
                if(catalogsAry.getJSONObject(1).get("cid") == catalogInfo.get("CatalogId")){
                    Logger.verifyEquals(price,catalogInfo.get("Price").getAsString(),"验证价格");
                    Logger.verifyEquals("0.0",catalogInfo.get("ActivityPrice").getAsString(),"验证活动价格");
                }
            }

        } catch (Exception e) {
            Logger.fail(e);
        }
    }
    
    
    /////////////////// 忽略case //////////////////////////
 // 渠道商
 	private static int rootUserId = AgentUsers.rootUserId;
 	private static String rootUserName = "NickautoTest";

 	@Test
 	@Category(P1.class)
 	@TestCase
    @Ignore
 	public void Tc_GetPriceByProdIdTradeIsolation_008() {
 		Logger.start(true, "查询限时抢八折后价格");
 		try {
 			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
 					rootUserName, false);
 			double price = 123.6;
 			addAgentProductBean.getCatalogList().forEach(a -> {
 				a.getAgentPriceList().forEach(b -> {
 					b.setAgentPrice(price);
 				});
 				a.setDirectPrice(price);
 			});
 			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
 			// 创建限时抢购活动
 			List<String> catalogList = new ArrayList<String>();
 			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(rootUserId,
 					productId);
 			selectProductDetails.getCatalogList().forEach(a -> {
 				catalogList.add(a.getCatalogId());
 			});
 			List<String> catalogs = new ArrayList<String>();

 			AddactivityBean initProductaddactivity = AgentProductCallService.initProductaddactivity(rootUserId,
 					productId, catalogList);
 			initProductaddactivity.getProductList().forEach(a -> {
 				a.getCatalogList().forEach(b -> {
 					catalogs.add(b.getCatalogId());
 					b.setDiscount(new BigDecimal("8"));
 				});
 			});
 			int activityId = AgentProductCallService.agentProductaddactivity(initProductaddactivity);
 			Thread.sleep(4000);

 			JsonObject callAndGetReturnData = getPriceByProdIdCall.callAndGetReturnData(oldBuyerId,
 					productId);
 			JsonObject asJsonObject1 = callAndGetReturnData.getAsJsonObject("Data").getAsJsonObject("PriceInfo")
 					.getAsJsonArray("Catalogs").get(0).getAsJsonObject();
 			JsonObject asJsonObject2 = callAndGetReturnData.getAsJsonObject("Data").getAsJsonObject("PriceInfo")
 					.getAsJsonArray("Catalogs").get(1).getAsJsonObject();
 			Logger.verifyEquals(price * 0.8, asJsonObject1.get("Price").getAsDouble(), "验证是否为八折价格");
 			Logger.verifyEquals(price * 0.8, asJsonObject2.get("Price").getAsDouble(), "验证是否为八折价格");
 			Logger.verifyEquals(price * 0.8, asJsonObject1.get("ActivityPrice").getAsDouble(), "验证是否为八折价格");
 			Logger.verifyEquals(price * 0.8, asJsonObject2.get("ActivityPrice").getAsDouble(), "验证是否为八折价格");
 			Logger.verifyEquals(price, asJsonObject1.get("QuotePrice").getAsDouble(), "验证是否为原价");
 			Logger.verifyEquals(price, asJsonObject2.get("QuotePrice").getAsDouble(), "验证是否为原价");

 		} catch (Exception e) {
 			Logger.fail(e);
 		}
 	}



}

